//
//  MIneHeadTableViewCell.m
//  MJApp
//
//  Created by scjh on 15/3/27.
//  Copyright (c) 2015年 wangliang. All rights reserved.
//

#import "MineHeadTableViewCell.h"

@interface MineHeadTableViewCell ()

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *descLabel;
@property (weak, nonatomic) IBOutlet UIButton *logoinBtn;

@end

@implementation MineHeadTableViewCell

+ (instancetype)initWithTableView:(UITableView *)tableView {
    
    static NSString *cellID = @"MineHeadTableViewCell";
    MineHeadTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        
        cell =  WL_XIB(@"MineHeadTableViewCell");
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.cellHigh = CGRectGetHeight(cell.frame);
    [cell Data];
    return cell;

}

- (void)Data {
    
    self.nameLabel.text = [userInfoTool share].nick_name;
    self.descLabel.text = [userInfoTool share].user_name;
    
    if ([userInfoTool share].ID) {
        
        self.logoinBtn.hidden = YES;
        NSString *headUrl = [NSString stringWithFormat:@"%@%@",kUrl,[userInfoTool share].head];
        if ([[userInfoTool share].head hasPrefix:@"http:"]) {
            
            headUrl = [userInfoTool share].head;
        }
        
        [self.headImageView sd_setImageWithURL:[NSURL URLWithString:headUrl]];
    }else {
        
        self.logoinBtn.hidden = NO;
    }
    
}

- (void)awakeFromNib {
    // Initialization code
    
    self.headImageView.layer.cornerRadius = CGRectGetHeight(self.headImageView.frame) / 2;
    self.headImageView.clipsToBounds = YES;
}

- (IBAction)login:(id)sender {
    
    if ([self.delegate respondsToSelector:@selector(homeCell:withInfo:)]) {
        [self.delegate homeCell:self withInfo:sender];
    }
}


- (IBAction)headPic:(id)sender {
    
    if ([self.delegate respondsToSelector:@selector(homeCell:withInfo:)]) {
        [self.delegate homeCell:self withInfo:sender];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setInfoDic:(NSDictionary *)infoDic {
    
    _infoDic = infoDic;
    
    if (infoDic == nil) {
        self.logoinBtn.hidden = NO;
        
    }else {
        
        self.logoinBtn.hidden = YES;
        if ([infoDic[@"photo"] count] > 0) {
            NSString *headUrl = [NSString stringWithFormat:@"%@%@",kUrl,infoDic[@"photo"][0][@"image"]];
            [self.headImageView sd_setImageWithURL:[NSURL URLWithString:headUrl]];
        }
        self.nameLabel.text = infoDic[@"user"][@"nick_name"];
        self.descLabel.text = infoDic[@"user"][@"user_name"];
    }
}

@end
